﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
using DTO;

namespace DAO
{
    //0712452
   public  class RutTienDAO
    {
       public static void ThemGiaoDich(GiaoDichDTO gdDto, PhieuRutTienTuTKDTO rutTienTuTKDto, string nhanVien, ref double LePhi)
       {
           SqlConnection cnn = KetNoiCSDL.TaoKetNoi();
           SqlCommand cmd = new SqlCommand("sp_Lay_phi_rut", cnn);

           cmd.CommandType = CommandType.StoredProcedure;

           cmd.Parameters.Add("@Ma_TK", SqlDbType.Char);
           cmd.Parameters.Add("@So_tien", SqlDbType.Money );
           cmd.Parameters.Add("@MaNV", SqlDbType.VarChar );
          
           cmd.Parameters["@Ma_TK"].Value = gdDto.MaTK ;
           cmd.Parameters["@So_tien"].Value = rutTienTuTKDto.SoTien;
       

           cmd.Parameters["@MaNV"].Value = nhanVien;

           cnn.Open();
           SqlDataReader dr = cmd.ExecuteReader();

           try
           {
               if (dr.Read())
               {
                   LePhi = double.Parse(dr["LePhi"].ToString());
               }
               cnn.Close();
           }
           catch (Exception ex)
           {
               if (cnn.State == ConnectionState.Open)
                   cnn.Close();
               throw ex;
           }
       }
    }
}
